<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--      &lt;!&ndash;部门数据&ndash;&gt;
            <el-col :span="4" :xs="24">
              <div class="head-container">
                <el-input
                  v-model="deptName"
                  placeholder="请输入部门名称"
                  clearable
                  size="small"
                  prefix-icon="el-icon-search"
                  style="margin-bottom: 20px"
                />
              </div>
              <div class="head-container">
                <el-tree
                  :data="deptOptions"
                  :props="defaultProps"
                  :expand-on-click-node="false"
                  :filter-node-method="filterNode"
                  ref="tree"
                  default-expand-all
                  @node-click="handleNodeClick"
                />
              </div>
            </el-col>-->
      <table>
        <tr>
          <td><span>知识点主题 :</span></td>
          <td>
            <el-select v-model="form.knowledge_type" placeholder="文档状态" clearable size="small">
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dict_value"
                :label="dict.dict_label"
                :value="dict.dict_label"
              />
            </el-select>
           </td>

        </tr>
        <br>
        <tr>
          <td>知识点类别:</td>
          <td><el-input v-model="form.knowledge_dime" placeholder="请输入活动类别" style="width: 240px"></el-input></td>
        </tr>
        <br>
        <tr>
          <td>知识点问题:</td>
          <td><el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="form.issue" placeholder="请输入活动标题" style="width: 240px"></el-input></td>
        </tr>
        <br>

        <tr>
          <td>知识点答案:</td>
          <td><el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="form.answer" placeholder="请输入活动地点" ></el-input></td>
        </tr>
        <br>

        <tr>
          <td><span>知识点状态:</span></td>
          <td>
            <el-select v-model="form.state" placeholder="文档状态" clearable size="small">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.dict_value"
                :label="dict.dict_label"
                :value="dict.dict_value"
              />
            </el-select>
          </td>

        </tr>
        <br/>
        <tr>
          <td></td>
          <td>
            <el-button type="primary" @click="submit">提交</el-button>
            <el-button type="info" @click="reset" style="margin-left: 30px;">重置</el-button></td>
        </tr>
      </table>

    </el-row>
  </div>
</template>

<script>


  import { list  , add} from "@/api/robot/base";
  import { listChannel , getChannel , addChannel , updateChannel ,delChannel,getParentChannel} from "@/api/monitor/channel";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import { listFile , getFile , addFile , updateFile ,delFile ,uploadFileImg} from "@/api/monitor/file";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  import Editor from '@/components/wangEditor'

  export default {
    name: "File",
    components: { Treeselect  ,Editor },
    data() {
      return {
        isClear: false,
        detail:"",
        user: {},
        sexs: [],
        option:[],
        id_card_type: [],
        status:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 默认密码
        initPassword: undefined,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 性别状态字典
        Options: [],
        // 岗位选项
        typeOptions: [],
        // 角色选项
        roleOptions: [],
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,

        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 1000,
          name: undefined,
          status: undefined
        },
        /*        // 表单校验
                rules: {
                  userName: [
                    { required: true, message: "用户名称不能为空", trigger: "blur" }
                  ],
                  nickName: [
                    { required: true, message: "用户昵称不能为空", trigger: "blur" }
                  ],

                  email: [
                    {
                      type: "email",
                      message: "'请输入正确的邮箱地址",
                      trigger: ["blur", "change"]
                    }
                  ],
                  phonenumber: [
                    {
                      pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                      message: "请输入正确的手机号码",
                      trigger: "blur"
                    }
                  ]
                }*/
      };
    },
    created() {
      this.getDicts("sys_base_state").then(response => {
        this.statusOptions = response.data.items;
      });
      this.getDicts("sys_knowledge_type").then(response => {
        this.typeOptions = response.data.items;
      });
    },

    methods: {
      change(val) {
        console.log(val)

      },
      submit () {
        add(this.form).then(rs =>{
          this.msgSuccess("新增成功");
        })
      },
      // 表单重置
      reset() {
        this.form = {
          subject_type: undefined,
          type: undefined,
          title: undefined,
          activity_time: undefined,
          position: undefined,
          content: undefined,
          activity_require: undefined,
          max_sign_up_time: undefined,
          sign_up_people_count: undefined,
          remarks: undefined,
        };
        this.resetForm("form");
      },
      /*文档附件上传*/
      handleAccessoryChangeIcon(file, fileList) {//选中文件触发的change事件
         console.log(file)
        const isJPG = file.raw.type === 'image/jpeg'
        const isPNG = file.raw.type === 'image/png'
        // const isLt2M = file.raw.size / 1024 / 1024 < 0.5  //限制上传文件的大小
        if (!isPNG && !isJPG) {
          this.$message.error('上传图片只能是 JPG/PNG 格式!')
          return false
        } else {
          this.form.accessory = URL.createObjectURL(file.raw);//赋值图片的url，用于图片回显功能
          this.uploadImg(file)//调用上传文件api接口
          this.$forceUpdate()
        }
      },


    }

  };
</script>

